package allinpay.yun.demo;

import ime.service.client.SOAClient;
import ime.service.util.RSAUtil;

import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;

/**
 * @Author: Jinch
 * @Description
 * @Date:Create in 2018/3/6 11:06
 */
public class DemoUtils {
    private static PublicKey publicKey;
    private static PrivateKey privateKey;

    public static void setParams(PublicKey _publicKey, PrivateKey _privateKey){
        publicKey = _publicKey;
        privateKey = _privateKey;
    }

    //RSA加密
    public static String rsaEncrypt(String signStr) throws Exception {
        try {
            System.out.println("rsaEncrypt start");

            RSAUtil rsaUtil = new RSAUtil((RSAPublicKey) publicKey, (RSAPrivateKey) privateKey);
            return rsaUtil.encrypt(signStr);
        } catch (Exception e) {
            System.out.println("rsaEncrypt error");
            e.printStackTrace();
            throw e;
        }
    }
}
